<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>数据列表</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="add">添加</el-button>
      </div>
    </el-card>

    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark">
      <el-table-column label="编号">
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column label="分类名称">
        <template slot-scope="scope">{{ scope.row.name }}</template>
      </el-table-column>
      <el-table-column label="级别">
        <template slot-scope="scope" v-if="scope.row.level==0">一级</template>
        <template slot-scope="scope" v-else-if="scope.row.level==1">二级</template>
      </el-table-column>
      <el-table-column label="商品数量">
        <template slot-scope="scope">{{ scope.row.productCount }}</template>
      </el-table-column>
      <el-table-column label="商品单位">
        <template slot-scope="scope">{{ scope.row.productUnit }}</template>
      </el-table-column>
      <el-table-column label="导航栏">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.navStatus"
                     @change="updatenavStatus(scope.row)"
                     :active-value=1 :inactive-value=0></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="是否显示">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.showStatus"
                     @change="updateshowStatus(scope.row)"
                     :active-value=1 :inactive-value=0></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="排序">
        <template slot-scope="scope">{{ scope.row.sort }}</template>
      </el-table-column>
      <el-table-column label="设置" width="250px">
          <template slot-scope="scope">
            <el-button size="mini" @click="toerji(scope.row.id)">查看下级</el-button>
            <el-button size="mini">转移商品</el-button>
          </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete( scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        style="float: right; padding: 3px 0" type="text"
        :current-page=pageNum
        :page-sizes="[3  , 10  , 15]"
        :page-size=pageSize
        layout="total, sizes, prev, pager, next, jumper"
        :total=total>
    </el-pagination>

  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {delect, findProductCategory, updatenavStatus, updateshowStatus} from "@/api/product/productCategory";

export default {
    //import引入的组件需要注入到对象中才能使用"
    components: {},
    props: {},
    data() {
      //这里存放数据"

      return {
        tableData:{},
        pageNum:1,
        pageSize:3,
        total:'',
      };
    },
    //计算属性 类似于data概念",
    computed: {},
    //监控data中的数据变化",
    watch: {},
    //方法集合",
    methods: {
      handleEdit(val){
          this.$router.push({path:'/product/updateproductCategory',query:{productCategory:val}})
      },
      updatenavStatus(val){
          updatenavStatus(val.id,val.navStatus).then(
              res=>{
                  this.$message.success(res.msg)
              }
          )
      },
      updateshowStatus(val){
          updateshowStatus(val.id,val.showStatus).then(
              res=>{
                  this.$message.success(res.msg)
              }
          )
      },
      toerji(val){
        this.$router.push({path:'/product/productCategoryEr',query:{id:val}})
      },
      handleDelete(val){
        delect(val).then(
            res=>{
              this.$message.success("删除成功")
              location.reload()
            }
        )
      },
      handleSizeChange(val) {
        this.pageSize=val
        this.findList()
      },
      handleCurrentChange(val) {
        this.pageNum=val
        this.findList()
      },
      findList(){
        findProductCategory(this.pageNum,this.pageSize).then(
          res=>{
            console.log(res)
            this.tableData=res.data.rows
            this.total=res.data.total
          }
        )
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）",
    created() {
      this.findList()
    },
    //生命周期 - 挂载完成（可以访问DOM元素）",
    mounted() {
    },
    beforeCreate() {
    }, //生命周期 - 创建之前",
    beforeMount() {
    }, //生命周期 - 挂载之前",
    beforeUpdate() {
    }, //生命周期 - 更新之前",
    updated() {
    }, //生命周期 - 更新之后",
    beforeDestroy() {
    }, //生命周期 - 销毁之前",
    destroyed() {
    }, //生命周期 - 销毁完成",
    activated() {
    } //如果页面有keep-alive缓存功能，这个函数会触发",
  };
</script>
<style scoped>

</style>
